package com.mldong.modules.sys.controller;

import com.mldong.auth.Perm;
import com.mldong.base.CommonPage;
import com.mldong.base.CommonResult;
import com.mldong.base.IdParam;
import com.mldong.base.IdsParam;
import com.mldong.modules.sys.dto.NoticePageParam;
import com.mldong.modules.sys.dto.NoticeParam;
import com.mldong.modules.sys.service.NoticeService;
import com.mldong.modules.sys.vo.NoticeVO;
import com.mldong.validation.Groups;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
/**
* <p>
    * 通知公告 前端控制器
    * </p>
*
* @author mldong
* @since 2022-10-23
*/
@RestController
@Api(tags = "通知公告管理")
@RequiredArgsConstructor
public class NoticeController {
    private final NoticeService noticeService;
    /**
     * 添加通知公告
     * @param param
     * @return
     */
    @PostMapping("/sys/notice/save")
    @ApiOperation(value = "添加通知公告")
    @Perm
    public CommonResult<?> save(@RequestBody @Validated({Groups.Save.class}) NoticeParam param) {
        noticeService.save(param);
        return CommonResult.ok();
    }
    /**
     * 删除通知公告
     * @param param
     * @return
     */
    @PostMapping("/sys/notice/remove")
    @ApiOperation(value = "删除通知公告")
    @Perm
    public CommonResult<?> remove(@RequestBody IdsParam param) {
        noticeService.removeBatchByIds(param.getIds());
        return CommonResult.ok();
    }
    /**
     * 修改通知公告
     * @param param
     * @return
     */
    @PostMapping("/sys/notice/update")
    @ApiOperation(value = "修改通知公告")
    @Perm
    public CommonResult<?> update(@RequestBody @Validated({Groups.Update.class}) NoticeParam param) {
        noticeService.update(param);
        return CommonResult.ok();
    }
    /**
     * 查询单个通知公告
     * @param param
     * @return
     */
    @PostMapping("/sys/notice/detail")
    @ApiOperation(value = "查询单个通知公告")
    @Perm
    public CommonResult<NoticeVO> detail(@RequestBody IdParam param) {
        NoticeVO notice = noticeService.findById(param.getId());
        return CommonResult.data(notice);
    }
    /**
     *分页查询通知公告列表
     * @param param
     * @return
     */
    @PostMapping("/sys/notice/page")
    @ApiOperation(value = "分页查询通知公告列表")
    @Perm
    public CommonResult<CommonPage<NoticeVO>> page(@RequestBody NoticePageParam param) {
        return CommonResult.data(noticeService.page(param));
    }
}
